{include file="public/header" /}

<div class="page">
    <div class="fixed-bar">
        <div class="item-title">
            <div class="subject">
                <h3>会员组</h3>
                <h5></h5>
            </div>
            {include file="public/admin_items" /}
        </div>
    </div>
    <div class="explanation" id="explanation">
        <div class="title" id="checkZoom">
            <h4 title="{$Think.lang.sc_explanation_tip}">{$Think.lang.sc_explanation}</h4>
            <span id="explanationZoom" title="{$Think.lang.sc_explanation_close}" class="arrow"></span>
        </div>
        <ul>
            <!--<li class="tips">“会员级别设置”提交后，当会员符合某个级别后将自动升至该级别，请谨慎设置会员级别</li>-->
            <!--<li class="tips">建议：一、级别应该是逐层递增，例如“级别2”所需经验值高于“级别1”；二、设置的第一个级别所需经验值应为0；三、信息应填写完整</li>-->
            <li class="tips">会员组分为 一级二级</li>
        </ul>
    </div>
    <form method="post" id="mg_form" name="mg_form" enctype="multipart/form-data" action="{:url('memberGroupSave')}">
        <table class="sc-default-table">
            <thead>
            <tr class="thead">
                <th class="align-center">会员组</th>
                <th class="align-center">一级佣金比例</th>
                <th class="align-center">二级佣金比例</th>
                <th class="align-center">一级价格比例</th>
                <th class="align-center">二级价格比例</th>
                <th class="align-center">是否可以查看保税货物信息<a onclick="setDefault()">初始化</a></th>
            </tr>
            </thead>
            <tbody id="mg_tbody">
                {notempty name="membergrade_list"}
                    {volist name="membergrade_list" id="d"}
                        {assign name="d_config" value="$d['group_config']" /}
                        <tr>
                            <td>
                                {$d.group_name}
                                <input type="hidden" name="id[]" value="{$d['id']}" />
                                <input type="hidden" name="member_group[]" value="{$d_config['member_group']}" />
                            </td>
                            <td>
                                <input type="text" sc_type="verify" name="commission_rate_1[]" value="{$d_config['commission_rate_1']}" class="w120" />
                            </td>
                            <td>
                                <input type="text" sc_type="verify" name="commission_rate_2[]" value="{$d_config['commission_rate_2']}" class="w120" />
                            </td>
                            <td>
                                <input type="text" sc_type="verify" name="price_1[]" value="{$d_config['price_1']}" class="w120" />
                            </td>
                            <td>
                                <input type="text" sc_type="verify" name="price_2[]" value="{$d_config['price_2']}" class="w120" />
                            </td>
                            <td>
                                <div class="onoff">
                                    <label for="read_bonded_goods_{$key}1" class="cb-enable {if condition="$d_config['read_bonded_goods'] eq 1"}selected{/if}">yes</label>
                                    <label for="read_bonded_goods_{$key}2" class="cb-disable {if condition="$d_config['read_bonded_goods'] eq 2"}selected{/if}">no</label>
                                    <input id="read_bonded_goods_{$key}1"  name="read_bonded_goods[{$key}]" value="1" type="radio" {if condition="$d_config['read_bonded_goods'] eq 1"} checked="checked"{/if}>
                                    <input id="read_bonded_goods_{$key}2"  name="read_bonded_goods[{$key}]" value="2" type="radio" {if condition="$d_config['read_bonded_goods'] eq 2"} checked="checked"{/if}>
                                </div>
                            </td>
                        </tr>
                    {/volist}
                {/notempty}
            </tbody>
            <tbody>
            <tr>
                <!--<td  colspan="3">-->
                <!--    <a id="add_membergrade" class="btn-add-nofloat marginleft" href="JavaScript:void(0);"> <span>新增等级</span> </a>-->
                <!--</td>-->
            </tr>
            </tbody>
            <tfoot>
            <tr>
                <td colspan="3"><a href="JavaScript:void(0);" class="btn" id="submitBtn"><span>{$Think.lang.sc_submit}</span></a></td>
            </tr>
            </tfoot>
        </table>
    </form>

    <script type="text/javascript">
        $(function () {
            var i = 0;
            var mg_tbody = '<tr>' +

                '<td><input type="hidden" name="id[]" value="" />' +

                '<input type="text" sc_type="verify" name="group_name[]" value="" class="w120" /></td>' +

                '<td><a onclick="remove_tr($(this));" href="JavaScript:void(0);">移除</a></td>' +
                '</tr>';

            $("#add_membergrade").click(function () {
                $('#mg_tbody > tr:last').after(mg_tbody.replace(/key/g, i));
                i++;
            });

            $('#submitBtn').click(function () {

                var result = true;
                var error = new Array();
                $("#mg_tbody").find("[sc_type='verify']").each(function () {
                    if (result) {
                        data = $(this).val();
                        if (!data) {
                            result = false;
                            //error.push('请将信息填写完整');
                            error = '请将信息填写完整';
                        }
                        //验证类型
                        if (result) {
                            var data_str = $(this).attr('data-param');
                            if (data_str) {
                                eval("data_str = " + data_str);
                                switch (data_str.type) {
                                    case 'int':
                                        result = (data = parseInt(data)) > 0 ? true : false;
                                        error = (result == false) ? (data_str.name + '应为整数') : '';
                                }
                            }
                        }
                    }
                });

                if (result) {
                    layer.confirm('确定要修改会员组设置吗？', {
                        btn: ['确定', '取消'],
                        title: false,
                    }, function () {
                        $('#mg_form').submit();
                    });
                } else {
                    layer.alert(error);
                }
            });
        })

        function remove_tr(o) {
            o.parents('tr:first').remove();
        }

        function edit(id, group_name) {
            let url = "{:url('edit_member_group')}?id=" + id
            scLayerOpen(url, '编辑会员组：' + group_name, 920, 713)
        }

        /**
         * 初始化
         */
        function setDefault() {
            let url = "{:url('setDefaultGroup')}"
            sc_ajaxget_confirm(url, '您确认要初始化会员组设置吗？','reload')
        }
    </script>
</div>
